package com.listen.service.DB;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.listen.common.DateFormatUtil;
import com.listen.common.HttpClientProxy;
import com.listen.common.HttpClientUtil;
import com.listen.model.User;
import com.listen.vo.ClassParmsVO;
import com.listen.vo.HeadParmsVO;
public class AnguanContinueServiceImplOld {


	private static final Logger log = LoggerFactory.getLogger(AnguanContinueServiceImplOld.class);
	private ConcurrentHashMap<String, Object>  resultMap = null;
	private HttpClientProxy instance = new HttpClientProxy();
	private CloseableHttpResponse response = null;
	private CloseableHttpClient httpClient = null;
	private String proxyInfo = null;
	private int flag;
	private String baseCookie = "";
	private String uid = "";
	private String paramid = "";
	private String __EVENTTARGET = "";
	private String __EVENTARGUMENT = "";
	private String __VIEWSTATE = "";
	private String __VIEWSTATEGENERATOR = "";
	
	public static void main(String args[]) throws InterruptedException{
		//int k = 3;
		//IPProxyNew proxy = new IPProxyNew();
		//List<String> ipAndPortList = proxy.getIpAndPortList(k);
		AnguanContinueServiceImplOld yanqi = new AnguanContinueServiceImplOld();
		User user = new User();
		user.setCode("362502198708270672");
		user.setZy("B");
		user.setZyName("三类继续教育");
		user.setAddress("http://urdt.cn:8181");
		user.setAllNum(19);
		user.setStatus(2);
		user.setPassword("888888");
		//String ip = "";
		/*for(int i=1;i<=19;i++) {
			user.setNowNum(i);
			for(int n = 0;n<k;n++) {
				ip = ipAndPortList.get(n);
				Map<String,Object> map = yanqi.lisetn(user,ip);
				if(map!=null&&"1".equals(map.get("successFlag"))) {
					break;
				}
				Thread.sleep(3000);
			}
		}*/
		for(int i=1;i<=19;i++) {
			user.setNowNum(i);
			yanqi.lisetn(user,"");
			Thread.sleep(3000);
		}
	}
	
	//听课业务
	public Map<String,Object> lisetn(User user,String ip){
		this.proxyInfo = ip;
		ClassParmsVO vo = new ClassParmsVO();
		resultMap = new ConcurrentHashMap<>();
		resultMap.put("successFlag", "0");
		resultMap.put("dayNum", "0");
		resultMap.put("addNum", "0");
		if(user.getStatus()==1)
			this.flag = 1;
		//状态为2已听完课，flag=3直接考试
		if(user.getStatus()==2)
			this.flag = 3;
		try {
			resolverHtml(vo,user);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}
	
	//跳转到具体专业登录页面,并抓取登錄參數
	private void resolverHtml(ClassParmsVO vo,User user){
		String url = user.getAddress();
		response = instance.sendHttpGet(httpClient, url, proxyInfo);
		HttpEntity entity = response.getEntity();  
		try {
			String html = EntityUtils.toString(entity, "UTF-8");
			Document document = Jsoup.parse(html);
		    Element parm1 = document.getElementById("__EVENTVALIDATION");
		    vo.set__eventvalidation(parm1.attr("value"));
		    Element parm2 = document.getElementById("__VIEWSTATE");
		    vo.set__viewstate(parm2.attr("value"));
		    login(vo,user);
		} catch (ParseException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			HttpClientUtil.getInstance().closeResource(response);
		}
	}
	
	//登录
	private void login(ClassParmsVO vo,User user){
		String code= user.getCode();
		String loginUrl = user.getAddress() + "/Login.aspx";
		Map<String, String> maps = new HashMap<String, String>();
		maps.put("__VIEWSTATE", vo.get__viewstate()); 
        maps.put("__EVENTVALIDATION",vo.get__eventvalidation());
        maps.put("txtUserName",code); 
        maps.put("txtPwd",user.getPassword());
        maps.put("ddlType", "2");//学员登录 
        maps.put("btnLogin", "");
        maps.put("txtLoginName", ""); 
        maps.put("txtDM", "");
        maps.put("txtFR", ""); 
        maps.put("zhjg", "");
        maps.put("zhfr", "");
        try {
        	HeadParmsVO head = new HeadParmsVO();
	        head.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
			head.setContentType("application/x-www-form-urlencoded");
			response = instance.sendHttpPost(httpClient, head, loginUrl, maps, proxyInfo);
        	int state = response.getStatusLine().getStatusCode();
        	vo.setLoginState(state);
        	if(state==302 || state==200){
        		Header[] hearders = response.getHeaders("Set-Cookie");
        		
        		String sessionIdCookie = hearders[0].getValue();
        		String sessionId = sessionIdCookie.substring(0, sessionIdCookie.indexOf(";") + 1);
        		vo.setSessionId(sessionId);
        		
        		String userIdCookie = hearders[1].getValue();
        		String userid = userIdCookie.substring(0, userIdCookie.indexOf(";") + 1);
        		vo.setUserid(userid);
        		
        		String infoCookies = hearders[2].getValue();
        		String info = infoCookies.substring(0, infoCookies.indexOf(";") + 1);
        		vo.setInfo(info);
        		this.uid = userid.substring(userid.indexOf("=")+1,userid.length()-1);
        		baseCookie = sessionId + userid + info;
        		if(flag==3){//只考试
        			submitPaper(vo,user);
        		}else if(flag==2 || flag == 1){
        			shipinSection(vo,user);//听课，考试
        		}else{
        			print(user.getZyName()+"-"+user.getCode()+"-登录成功后跳转标识异常-flag="+flag);
        			logout(vo,user);
        		}
        	}else{
        		print(user.getZyName()+"-"+user.getCode()+"-登录失败--->"+state);
        		logout(vo,user);
        	}
		} catch (Exception e) {
			printError(user.getZyName()+"-"+user.getCode()+"-登录异常--->"+e);
			logout(vo,user);
		}finally{
			HttpClientUtil.getInstance().closeResource(response);
		}
	}
	
	/*public void SMN_VIP(ClassParmsVO vo,User user) {
		String path = user.getAddress() +"/SMN_VIP.aspx";
		HeadParmsVO heads = new HeadParmsVO();
		heads.setCookie(cookie);
		heads.setUpgradeInsecureRequests("1");
		try {
			response = instance.sendHttpGet(httpClient, heads, path, proxyInfo);
			int status =  response.getStatusLine().getStatusCode();
			if(status == 200) {
			}else {
				print(user.getZyName()+"-"+user.getCode()+"-SMN_VIP调用失败--->"+status);
			}
		} catch (Exception e) {
			printError(user.getZyName()+"-"+user.getCode()+"-SMN_VIP调用异常--->"+e);
			logout(vo,user);
		}finally{
			HttpClientUtil.getInstance().closeResource(response);
		}
	}*/
	
	//点击视频教程
	public void shipinSection(ClassParmsVO vo,User user) {
		String zyName = user.getZyName();
		int i = user.getNowNum();
		String shipinSection_url = user.getAddress() + "/ShiPinJiaoCheng/shipinSection.aspx";
		user.setReferer(shipinSection_url);
		String cookie = this.baseCookie;
		HeadParmsVO heads = new HeadParmsVO();
		heads.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
		heads.setCookie(cookie);
		heads.setUpgradeInsecureRequests("1");
		try {
			response = instance.sendHttpGet(httpClient,heads, shipinSection_url,proxyInfo);
			int state = response.getStatusLine().getStatusCode();
			//Thread.sleep(1000);
			if(state == 200){
				//print(zyName+"-"+ user.getCode() +" 第"+i +"个视频,shipinSection-->方法请求成功:"+state);
				HttpEntity entity = response.getEntity();
				String html = EntityUtils.toString(entity);
				Document document = Jsoup.parse(html);
				
				Element parm3 = document.getElementById("__VIEWSTATE");
				this.__VIEWSTATE = parm3.attr("value");
				
				Element parm4 = document.getElementById("__VIEWSTATEGENERATOR");
				this.__VIEWSTATEGENERATOR = parm4.attr("value");
				isStudy(vo,user);
			}else{
				print(zyName+"-"+ user.getCode() +" 第"+i +"个视频,shipinSection-->方法请求失败:"+state);
			}
		} catch (Exception e) {
			printError(user.getZyName()+"-"+user.getCode()+"-shipinSection-->方法请求异常:"+e);
			logout(vo,user);
		}finally {
			HttpClientUtil.getInstance().closeResource(response);
		}
		
	}
	//开始学习
	private void isStudy(ClassParmsVO vo,User user) {
		int i = user.getNowNum();
		int end = i%10;
		String id = "";
		if(i < 10) {
			id = "1000"+end;
		}else if(i >=10 && i <14){
			id = "1030"+(end+1);
		}else if(i >=14 && i <18){
			id = "1040"+(end-3);
		}else{
			id = "1050"+((i+3)%10);
		}
		this.paramid = id;
		String isStudy_url = user.getAddress() + "/myclass/IsStudy.aspx?id="+paramid;
		//System.out.println(isStudy_url);
		HeadParmsVO heads = new HeadParmsVO();
		heads.setCookie(this.baseCookie);
		heads.setReferer(user.getReferer());
		user.setReferer(isStudy_url);//设置referer
		try {
			Thread.sleep(1000);
			response = instance.sendHttpGet(httpClient,heads, isStudy_url,proxyInfo);
			int state = response.getStatusLine().getStatusCode();
			//String resMsg = EntityUtils.toString(response.getEntity(), "UTF-8");
			//System.out.println(resMsg);
			if(state == 200){
				//print(user.getZyName()+"-"+ user.getCode() +" 第"+i +"个视频,-isStudy-->请求成功:"+state);
				shipinSectionPost(vo,user);
			}else{
				print(user.getZyName()+"-"+ user.getCode() +" 第"+i +"个视频,-isStudy-->请求失败:"+state);
			}
		} catch (Exception e) {
			printError(user.getZyName()+"-"+user.getCode()+"-isStudy-->请求异常:"+e);
			logout(vo,user);
		}finally {
			HttpClientUtil.getInstance().closeResource(response);
		}
	}
		
	public void shipinSectionPost(ClassParmsVO vo,User user) {
		String shipinSectionPost_url = user.getAddress() + "/ShiPinJiaoCheng/shipinSection.aspx";
		HeadParmsVO heads = new HeadParmsVO();
	    heads.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
	    heads.setAcceptEncoding("gzip, deflate");
	    heads.setAcceptLanguage("zh-CN,zh;q=0.9");
	    heads.setContentType("application/x-www-form-urlencoded");
	    heads.setxRequestedWith("XMLHttpRequest");
	    heads.setCookie(this.baseCookie);
    	heads.setReferer(user.getReferer());
    	heads.setUpgradeInsecureRequests("1");
    	heads.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36");
    	int nowNum = user.getNowNum();
    	Map<String, String> maps = new HashMap<String, String>();
    	maps.put("__EVENTTARGET", this.__EVENTTARGET);
		maps.put("__EVENTARGUMENT", this.__EVENTARGUMENT);
        maps.put("__VIEWSTATE", this.__VIEWSTATE); 
        maps.put("__VIEWSTATEGENERATOR",this.__VIEWSTATEGENERATOR);
        maps.put("dr1","103");
        int k = (nowNum-1)%10;
        String key = "rep1:ctl"+ k +"Button1";
        maps.put(key, "进入听课");
        
        user.setReferer(shipinSectionPost_url);
        try {
        	Thread.sleep(1000);
        	response = instance.sendHttpPost(httpClient, heads, shipinSectionPost_url, maps, proxyInfo);
        	int status = response.getStatusLine().getStatusCode();
    		if(status == 200) {
    			//print(user.getZyName()+"-"+user.getCode() +"-第"+nowNum+"个视频-shipinSection-post--> 请求成功"+status);
    			watchVideo(vo,user);
    		}else {
    			print(user.getZyName()+"-"+user.getCode() +"-第"+nowNum+"个视频-shipinSection-post--> 请求成功"+status);
    		}
		} catch (Exception e) {
			print(user.getZyName()+"-"+user.getCode() +"-第"+ nowNum +"个视频-shipinSection-post--> 请求异常"+e);
		}finally {
			instance.closeResource(response, httpClient);
		}
	}
		
	public void watchVideo(ClassParmsVO vo,User user){
		int nowNum = user.getNowNum();
		String watchVideo_url = user.getAddress() +"/myclass/WatchVideo.aspx?id="+this.paramid;
		HeadParmsVO heads = new HeadParmsVO();
	    heads.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
	    heads.setAcceptEncoding("gzip, deflate");
	    heads.setAcceptLanguage("zh-CN,zh;q=0.9");
	    heads.setCookie(this.baseCookie);
    	heads.setReferer(user.getReferer());
    	heads.setUpgradeInsecureRequests("1");
    	heads.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36");
    	try {
    		Thread.sleep(1000);
    		response = instance.sendHttpGet(httpClient, heads, watchVideo_url, proxyInfo);
    		int status = response.getStatusLine().getStatusCode();
    		if(status == 200) {
				user.setReferer(watchVideo_url);
				//print(user.getZyName()+"-"+user.getCode() +"-第"+ nowNum +"个视频-watchVideo--> 请求成功"+status);
				updateClassState(vo,user);
    		}else {
    			print(user.getZyName()+"-"+user.getCode() +"-第"+ nowNum +"个视频-watchVideo--> 请求失败"+status);
    		}
		} catch (Exception e) {
			print(user.getZyName()+"-"+user.getCode() +"-第"+ nowNum +"个视频-watchVideo-->"+e);
		}finally {
			instance.closeResource(response, httpClient);
		}
	}
	
	/*private void videoComplete(ClassParmsVO vo,User user) {
		int nowNum = user.getNowNum();
    	String cookie = this.baseCookie + "totaltime=2957; url="+user.getReferer()+"; checkUid="+this.uid+"; PC1=%u6210%u529F; PC2=%u6210%u529F; PC4=%u6210%u529F; nowtime=2899";
    	HeadParmsVO heads = new HeadParmsVO();
	    heads.setContentType("application/json;utf-8");
	    heads.setAcceptEncoding("gzip, deflate");
	    heads.setAcceptLanguage("zh-CN,zh;q=0.9");
	    heads.setCookie(cookie);
    	heads.setxRequestedWith("XMLHttpRequest");
    	System.out.println(cookie);
    	String id = "";
    	if(nowNum < 10)
    		id = "1000"+nowNum;
    	else if(nowNum >=10 && nowNum < 14) {
    		id = "1030"+ (nowNum%10+1);
    	}else if(nowNum >=14 && nowNum < 18) {
    		id = "1040"+ (nowNum%10-3);
    	}else if(nowNum >= 18) {
    		id = "1050" + (nowNum%10-7);
    	}
    	try {
    		String completeUrl = user.getAddress() + "/myclass/VideoComplete.aspx?id="+id+"&vid=103&tag=True";
    		System.out.println(completeUrl);
    		response = instance.sendHttpGet(httpClient, heads, completeUrl, proxyInfo);
    		String resMsg = EntityUtils.toString(response.getEntity(), "UTF-8");
    		System.out.println(resMsg);
    		int status = response.getStatusLine().getStatusCode();
    		if(status == 200) {
    			user.setReferer(completeUrl);
    			print(user.getZyName()+"-"+user.getCode() +"-第"+ nowNum +"个视频-videoComplete--> 请求成功"+status);
    			updateClassState(vo,user);
    		}else {
    			print(user.getZyName()+"-"+user.getCode() +"-第"+ nowNum +"个视频-videoComplete--> 请求失败"+status);
    		}
		} catch (Exception e) {
			print(user.getZyName()+"-"+user.getCode() +"-第"+ nowNum +"个视频-watchVideo--> 请求异常"+e);
		}finally {
			instance.closeResource(response, httpClient);
		}
	}*/
	
	
	//修改课件状态
	private void updateClassState(ClassParmsVO vo,User user){
 		String code = user.getCode();
		String zyName = user.getZyName();
		int i = user.getNowNum();
		int classid = 0;
		if(i==1) {
			classid=220;
		}if(i>=2 && i<=7){
			classid=210+i;
		}if(i==8 || i==9){
			classid = 216+i;
		}if(i>=10 && i<=13){
			classid = 131 + i;
		}if(i>=14 && i<=17){
			classid = 134 + i;
		}if(i >=18 && i<=19){
			classid = 137+i;
		}if(i == 20)
			classid = 226;
		try {
			Thread.sleep(1000);
			//st构建
			String st = DateFormatUtil.getDateAnyMinuteBeforeFoer8(40);
			st = st.replaceAll(" ", "%20").replaceAll(":", "%3A");
			String cookie = this.baseCookie +"totaltime=2981;checkUid="+uid+";nowtime=2881;st="+st;
			String allUrl = user.getAddress() + "/EntpClass/Xtyl.ashx?classid="+ classid +"&uid="+uid;
			HeadParmsVO heads = new HeadParmsVO();
			heads.setAccept("*/*");
			heads.setxRequestedWith("XMLHttpRequest");
			heads.setContentType("application/json;utf-8");
			heads.setAcceptEncoding("gzip, deflate");
			heads.setCookie(cookie);
			response = instance.sendHttpGet(httpClient, heads, allUrl, proxyInfo);
			int state = response.getStatusLine().getStatusCode();
			if(state == 200){
				print(zyName+"-"+ code +" 第"+i +"个视频成功播放完!");
				resultMap.put("successFlag", "1");
				resultMap.put("dayNum", "1");
				resultMap.put("addNum", "1");
				if(user.getAllNum()==i)
					user.setStatus(2);
			}else{
				print(zyName+"-"+ code +" 第"+i +"个视频播放失败!state="+state);
			}
		} catch (Exception e) {
			printError(zyName+"-"+ code +" 第"+i +"个视频"+e);
		}finally{
			instance.closeResource(response, httpClient);
			HttpClientUtil.getInstance().closeResource(response);
			if(flag==2)//听课并考试
				submitPaper(vo,user);
			else//只听课，听完退出登录
				logout(vo,user);
		}
	}
	
	/*private void testPaper(ClassParmsVO vo,User user) {
		String testUrl = user.getAddress() + "/TR_TestPaper.aspx";
		String info = vo.getInfo();
		String sessionId = vo.getSessionId();
		String userid = vo.getUserid();
		String cookie = sessionId + userid + info;
		HeadParmsVO heads = new HeadParmsVO();
		heads.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp");
		heads.setCookie(cookie);
		response = instance.sendHttpGet(httpClient, heads, testUrl, proxyInfo);
		int state = response.getStatusLine().getStatusCode();
		try {
			Thread.sleep(10000);
			if(state == HttpStatus.SC_OK){
				HttpEntity entity = response.getEntity();
				String html = EntityUtils.toString(entity, "UTF-8");
				Document document = Jsoup.parse(html);
				Element parm1 = document.getElementById("_thid");
				vo.setPid(parm1.attr("value"));
				Element parm2 = document.getElementById("Hidden1");
				vo.setQid(parm2.attr("value"));
				Element parm3 = document.getElementById("Hidden2");
				vo.setHid(parm3.attr("value"));
				submitPaper(vo,user);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}*/
	
	//提交试卷，考试
	private void submitPaper(ClassParmsVO vo,User user){
		String userid = vo.getUserid();
		String info = vo.getInfo();
		String sessionId = vo.getSessionId();
		String code = user.getCode();
		String zyName = user.getZyName();
		try {
			//设置答案
			String uid = userid.substring(userid.indexOf("=")+1,userid.length()-1);
			String cookie = sessionId + userid + info +"totaltime=2881;checkUid="+uid+";nowtime=2856";
	        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();  
	        params.add(new BasicNameValuePair("Pid", vo.getOld_pid()));  
	        params.add(new BasicNameValuePair("Qid", vo.getOld_qid()));
	        params.add(new BasicNameValuePair("Hid",vo.getOld_hid()));  
	        params.add(new BasicNameValuePair("Pwr",vo.getOld_Pwr()));  
	        params.add(new BasicNameValuePair("Qwr",getQwr()));  
	        params.add(new BasicNameValuePair("Hwr", vo.getOld_Hwr()));
	        System.out.println("pid:"+vo.getOld_pid());
	        System.out.println("qid:"+vo.getOld_qid());
	        System.out.println("hid:"+vo.getOld_hid());
	        System.out.println("Pwr:"+vo.getOld_Pwr());
	        System.out.println("Qwr:"+vo.getOld_Qwr());
	        System.out.println("Hwr:"+vo.getOld_Hwr());
	        //要传递的参数.  
	        String url = user.getAddress() + "/MarkTJ.aspx?" + URLEncodedUtils.format(params,"UTF-8");
	        
	        HeadParmsVO heads = new HeadParmsVO();
	        heads.setAccept("*");
	        heads.setxRequestedWith("XMLHttpRequest");
	        heads.setCookie(cookie);
	        response = instance.sendHttpGet(httpClient, heads, url, proxyInfo);
	        String resMsg = EntityUtils.toString(response.getEntity(), "UTF-8");
	        int state = response.getStatusLine().getStatusCode();
	        if (state == HttpStatus.SC_OK) {
	        	print(zyName+"-"+ code +"-考试成功，本次考试成绩为："+resMsg);
	        	resultMap.put("successFlag", "1");
	        	user.setStatus(3);
	        }else{
            	print(zyName+"-"+ code +"-试卷提交失败！------->state="+state);
            }
		} catch (Exception e) {
			printError(zyName+"-"+code+"-生成试卷异常--->"+e);
		}finally{
			instance.closeResource(response, httpClient);
			logout(vo,user);
		}
	}
	
	//安全生产知识培训平台：退出登录
	private void logout(ClassParmsVO vo,User user){
		String userid = vo.getUserid();
		String info = vo.getInfo();
		String sessionId = vo.getSessionId();
		try {
			String uid = userid.substring(userid.indexOf("=")+1,userid.length()-1);
			String path = user.getAddress() + "/Logout.aspx";
			String cookie = sessionId + userid + info +"totaltime=2981;checkUid="+uid+";nowtime=2931";
			HeadParmsVO heads = new HeadParmsVO();
			heads.setAccept("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
			heads.setCookie(cookie);
			response = instance.sendHttpGet(httpClient, heads, path, proxyInfo);
			int state = response.getStatusLine().getStatusCode();
			//System.out.println("logout state="+state);
			if(state == 200 || state == 302){
				//print("退出登录成功!");
			}else{
				//print("退出登录失败!");
			}
		} catch (Exception e) {
			print("退出登录异常--->"+e);
		}finally{
			instance.closeResource(response, httpClient);
		}
	}
	//获得10个1-100随机数，根据数值范围设置ABCD
	public static String getQwr(){
		String qwr = "";
		Set<Integer> set=new HashSet<Integer>();
		while(true){
			int num = (int)(Math.random()*100+1);
			if(set.contains(num))
				continue;
			set.add(num);
			if(num > 75)
				qwr = qwr + "D,";
			if(num >50 && num <= 75)
				qwr = qwr + "C,";
			if(num >25 && num <= 50)
				qwr = qwr + "B,";
			if(num >=1 && num <= 25)
				qwr = qwr + "A,";
			if(set.size()==10)
				break;
		}
		return "A,A,D,C,D,C,C,A,D,D,"+qwr;
	}
	
	private void print(String msg){
		resultMap.put("msg", msg);
		log.info(msg);
	}
	
	private void printError(String errMsg){
		resultMap.put("errMsg", errMsg);
		log.error(errMsg);
	}

}
